<template>
  <basic-container>
    <dataList ref="dataList" placeholder="请输入项目名称" :pageInfo="pager" :listData="tableData" searchName="projectName" :menuList="['add','export']" :filterList="filterList" @menu-click="handleMenuClick">
      <el-table :data="tableData" align="left" ref="multipleTable">
        <el-table-column label="项目编号" prop="projectCode" width="180" />
        <el-table-column label="项目名称" prop="projectName" width="200" show-overflow-tooltip />
        <el-table-column label="项目街道" prop="projectStreet" width="160" show-overflow-tooltip />
        <el-table-column label="项目社区" prop="communityName" width="160" show-overflow-tooltip />
        <el-table-column label="项目位置" prop="addressInfo" width="200" show-overflow-tooltip />
        <el-table-column label="管理权属" prop="manageUnit" width="160" show-overflow-tooltip>
          <template slot-scope="scope">{{getCardTypeValue(scope.row.manageUnit,manageUnits)}}</template>
        </el-table-column>
        <el-table-column label="开发单位" prop="constructionUnit" width="200" show-overflow-tooltip />
        <el-table-column width="160" label="操作" fixed="right">
          <template slot-scope="scope">
            <el-button type="text" @click="handleLookConstruction(scope.row)">查看</el-button>
            <el-button type="text" @click="handleConstruction(scope.row)">编辑</el-button>
            <el-button type="text" @click="handleToTransfer(scope.row)">提交</el-button>
          </template>
        </el-table-column>
      </el-table>
    </dataList>
     <custom-export v-bind="exportData" :exportParams="params" ref="provideExport" />
  </basic-container>
</template>

<script>
import { mapGetters } from 'vuex'
import { underconstructionPage, turnOver } from '../api/construction'
import CacheParams from "@/assets/vue-mixin/CacheParams";
export default {
  name: "project-index",
  mixins: [CacheParams],
  provide () {
    return {
      initList: this.getListData
    };
  },
  beforeMount () {
    this.getListData();
  },
  mounted () {
    this.add_construction = this.permissions["underconstruction_edit"];
    this.export_construction = this.permissions["underconstruction_get"];
    this.manageUnits = this.getDict("administrative_office");
  },
  data () {
    return {
      // hxf-0827-表单绑定
      tableData: [],
      // 请求参数
      params: {
        current: 1,
        size: 20,
        projectName: ""
      },
      // 选中的数据
      selectDataArr: [],
      // 分页
      pager: {
        total: 0, // 总页数
        current: 1, // 当前页数
        size: 20 // 每页显示多少条
      },
      // 页面loading
      loading: false,
      filterList: [
        /* {
           label: "物业大类",
           inputType: "dict",
           dictName: "project_types",
           name: "projectType",
           multiple: true
         },*/
        {
          label: "项目街道",
          inputType: "dict",
          dictName: "streets",
          name: "projectStreet",
          linkName: 'communityName',
        },
        {
          label: "项目社区",
          inputType: "select",
          children: this.getDict('community_names'),
          name: "communityName",
          multiple: true
        },
        {
          label: '是否有地图坐标', inputType: 'select', name: 'isMapCoordinates', multiple: false, children: [
            { label: '是', value: '1' },
            { label: '否', value: '0' }
          ]
        }
      ],
      // hxf-0901-权限配置初始值
      add_construction: false,
      export_construction: false,
      //hxf-0901-传个编辑的标识
      isEdit: "",
      manageUnits: []
    };
  },
  computed: {
    ...mapGetters(["permissions"]),
    // 导出数据配置
    exportData () {
      return {
        url: "/api/underconstruction/download",
        exportName: "在建项目信息",
        listName: "fields",
        exportData: [
          {field: "项目编号", val: "project_code" },
          {field: "项目名称", val: "project_name" },
          {field: "曾用名", val: "used_name" },
          {field: "管理权属", val: "manage_unit" },
          {field: "项目国家编码", val: "project_country_code" },
          {field: "建设单位", val: "construction_unit" },
          {field: "联系人", val: "contact_name" },
          {field: "联系电话", val: "contact_phone" },
          {field: "围栏坐标", val: "fence_coordinates" },
          {field: "地图坐标", val: "map_coordinates" },
          {field: "项目备注", val: "remarks" },
          {field: "宗地号", val: "parcel_num" },
          {field: "宗地面积", val: "parcel_area" },
          {field: "土地用途", val: "land_use" },
          {field: "土地合同号", val: "land_contract_num" },
          {field: "街道", val: "street" },
          {field: "社区", val: "community" },
          {field: "详细地址", val: "address_info" },
          // {field: "导出全部配套物业", val: "all_fac" }
        ]
      };
    }
  },
  methods: {
    // hxf-0903-分页接口
    getListData (params = {}) {
      this.loading = true;
      let requestData = { ...this.params, ...params };
      underconstructionPage(requestData)
        .then(res => {
          const { current, size, total, records } = res.data.data;
          this.tableData = records;
          this.params = requestData;
          this.pager = { total, current, size };
        })
        .finally(() => {
          this.loading = false;
        });
    },
    // 菜单点击监听
    handleMenuClick (type) {
      switch (type) {
        case "add":
          this.$router.push({ name: "construction_add" });
          break;
        case "export":
         this.$refs.provideExport.show()
          break;
        default:
          this.$message(type);
          break;
      }
    },
    // hxf-0827-导出
    exportTable () {
      this.publicExport('规划物业', '/api/underconstruction/download', this.params)
    },
    // hxf-0827-编辑
    handleConstruction (row) {
      this.$router.push({
        name: "construction_edit",
        query: { isEdit: row.projectId }
      });
    },
    // hxf-0904-推进到移交
    handleToTransfer (row) {
      this.$confirm(
        "该动作是将此项目提交到“项目接收” ，您确认要继续操作？",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      ).then(() => {
        turnOver(row.projectId).then(res => {
          if (res.data.code === 0) {
            this.$message.success("已成功推送到项目接收！");
            this.getListData();
          }
        });
      });
    },
    getCardTypeValue (num, sum) {
      let arr = sum.filter(e => e.value === num);
      if (arr.length > 0) {
        return arr[0].label;
      } else {
        return num;
      }
    },
    handleLookConstruction(row) {
			this.$router.push({
				name: "construction_look",
				query: { projectId: row.projectId }
			});
		},

  }
};
</script>
